home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Design
/
WB Collection.iso
/
datatypes
/
dfadt
/
source
/
dfadt_prefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-07
|
4KB
|
206 lines
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by Dirk Federlein
**
** File : Work:programming/dfa/Sourcen_V2.3/Datatypes/dfadt_prefs.c
** Created on : Freitag, 17.03.95 22:56:44
** Created by : Dirk Federlein
** Current revision : V1.0
**
**
** Purpose
** -------
** Reads the env:DFADT.prefs file.
**
** Revision V1.0
** --------------
** created on Freitag, 17.03.95 22:56:44 by Dirk Federlein. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
#include "all_includes.h"
#include "dfadt.h"
/*
Format:
FIELDNAME FIELDDESC FIELDLENGTH
where FIELDNAME may be any of
SALUTATION
FIRSTNAME
NAME
CO
STREET
ZIP
CITY
STATE
COUNTRY
BIRTHDAY
PHONE
FAX
EMAIL1
EMAIL2
EMAIL3
COMMENT
FIELDDESC may be any string and is meant to describe the contents of the field.
Please notice that the datatype does NOT insert any spaces between the columns,
so if you want nothing but the field CONTENTS but e.g. ONE SPACE between the
columns, you have to set the FIELDDESC of all but the first field to " ". The
first field should get a "".
*/
#define ARGTEMPLATE "FieldName/A,FieldDescription/A,FieldLength/A/N"
static char linebuffer[1024];
static char * FIELDNAMES[] =
{ "SALUTATION",
"FIRSTNAME",
"NAME",
"CO",
"STREET",
"ZIP",
"CITY",
"STATE",
"COUNTRY",
"BIRTHDAY",
"PHONE",
"FAX",
"EMAIL1",
"EMAIL2",
"EMAIL3",
"COMMENT",
NULL
};
static char * DEFAULT_DELIM = " ";
// #define DEBUG
#ifdef DEBUG
#define D(x) x
void kprintf(const char * fmt,...);
#else
#define D(x)
#endif
struct FIELDDESC * dfadt_readprefs(struct DDTData * dd)
{
BPTR fp;
char * lineptr;
long i,k;
long result[3] = { 0 };
struct EasyStruct ErrorES =
{
sizeof (struct EasyStruct), 0, NULL, NULL, NULL
};
struct FIELDDESC * fdesc = NULL;
struct RDArgs * rdargs = NULL;
struct RDArgs fakerdargs = {0};
D(kprintf("dfadt_readprefs():\n"));
D(kprintf("dfadt_readprefs(): DDTData = 0x%lx\n", dd));
D(kprintf("dfadt_readprefs(): DDTData->ddt_Pool = 0x%lx\n", dd->ddt_Pool));
if (fp = Open(DFADTPREFS, MODE_OLDFILE))
{
D(kprintf("dfadt_readprefs(): PrefsFile = 0x%lx\n", fp));
if (fdesc = AllocPooled(dd->ddt_Pool, 20*sizeof(struct FIELDDESC)))
{
D(kprintf("dfadt_readprefs(): fdesc = 0x%lx\n", fdesc));
k = 0;
while ((k<19) && (lineptr = FGets(fp, linebuffer, 1023)))
{
D(kprintf("dfadt_readprefs(): k = %ld\n", k));
fakerdargs.RDA_Source.CS_Buffer = lineptr;
fakerdargs.RDA_Source.CS_Length = strlen(lineptr);
fakerdargs.RDA_Source.CS_CurChr = 0;
result[0] = result[1] = result[2] = 0;
if (rdargs = ReadArgs(ARGTEMPLATE, result, & fakerdargs))
{
D(kprintf("dfadt_readprefs(): result[0] = <%s>\n", (char *) result[0]));
D(kprintf("dfadt_readprefs(): result[1] = <%s>\n", (char *) result[1]));
D(kprintf("dfadt_readprefs(): result[2] = %ld\n", * ((ULONG*)( result[2]))));
if (result[0]) // description
{
for (i=0; i<16; i++)
{
if (stricmp((char *)result[0], FIELDNAMES[i]) == 0)
fdesc[k].offset = i;
}
}
if (result[1])
{
if (fdesc[k].description = AllocPooled(dd->ddt_Pool, strlen((char*)result[1])+1))
strcpy(fdesc[k].description, (char*)result[1]);
else
fdesc[k].description = DEFAULT_DELIM;
}
if (result[2])
{
if (result[2] > 0)
fdesc[k].length = * ((ULONG*) (result[2]));
else
fdesc[k].length = 10;
}
FreeArgs(rdargs);
}
else
{
ErrorES.es_Title = "DFA Datatype - Syntax Error";
ErrorES.es_TextFormat = "Syntax Error in line %ld\nof the preferences file.\nUsing default format...";
ErrorES.es_GadgetFormat = "Ok";
EasyRequest(NULL, &ErrorES, NULL, k+1);
FreePooled(dd->ddt_Pool, fdesc, 20*sizeof(struct FIELDDESC));
fdesc = NULL;
goto end;
}
k++;
}
D(kprintf("dfadt_readprefs(): (last) k = %ld\n", k));
fdesc[k].offset = -1L;
fdesc[k].description = NULL;
fdesc[k].length = 0;
end:
;
}
Close(fp);
}
return(fdesc);
}